﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MathLab.Messaging;

namespace MathLab.Parsing
{
    class WriteToFileParser
    {
        private string _fileName;
        private List<string> _arrays;

        public void parse(string input)
        {
            arrays = new List<string>();

            bool nameFlag = false;
            bool arraysFlag = false;

            StringBuilder name = new StringBuilder();

            for (int i = 0; i < input.Length; i++)
            {
                string s = input[i].ToString();

                switch (s)
                {
                    case "(":
                        nameFlag = true;
                        break;
                    case ")":
                        fileName = name.ToString();
                        name = new StringBuilder();
                        nameFlag = false;
                        break;
                    case Literals.ARRAY_DECLARATION_START:
                        arraysFlag = true;
                        break;
                    case Literals.ARRAY_DECLARATION_END:
                        arraysFlag = false;
                        break;
                    case " ":
                        if (!"".Equals(name.ToString()))
                        {
                            arrays.Add(name.ToString());
                            name = new StringBuilder();
                        }
                        break;
                    default:
                        if (nameFlag || arraysFlag)
                        {
                            name.Append(s);
                        }
                        break;
                }
            }
            arrays.Add(name.ToString());
        }

        public string fileName
        {
            get
            {
                return _fileName;
            }
            set
            {
                _fileName = value;
            }
        }

        public List<string> arrays
        {
            get
            {
                return _arrays;
            }
            set
            {
                _arrays = value;
            }
        }
    }
}
